package logic

import (
	"context"
	"errors"
	"pro/models/mysql"

	"pro/prorpc/internal/svc"
	"pro/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorDelLogic {
	return &DoctorDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorDelLogic) DoctorDel(in *prorpc.DoctorDelRequest) (*prorpc.DoctorDelResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.Doctor
	mysql.DB.Debug().Where("id=?", in.DoctorId).Find(&doctor)
	if doctor.ID == 0 {
		return nil, errors.New("患者不存在")
	}

	mysql.DB.Debug().Where("id=?", in.DoctorId).Delete(&mysql.Doctor{})

	return &prorpc.DoctorDelResponse{}, nil
}
